#include "Key.h"

unsigned char Key_Number;
unsigned char Key(void)
{
	unsigned char Temp;
	Temp = Key_Number;
	Key_Number = 0;
	return Temp;
}

unsigned char Key_GetState(void)
{
	unsigned char KeyNum = 0;
	if (P3_1 == 0){KeyNum = 1;};
	if (P3_0 == 0){KeyNum = 2;};
	if (P3_2 == 0){KeyNum = 3;};
	if (P3_3 == 0){KeyNum = 4;};
	return KeyNum;
}

void Key_Loop(void)//此函数给定时器调用，避免主函数调用，防止冲突
{
	static unsigned char LastState,NowState;
	LastState = NowState;
	NowState = Key_GetState();
	if (LastState == 1 && NowState == 0)
	{
		Key_Number = 1;
	}
	if (LastState == 2 && NowState == 0)
	{
		Key_Number = 2;
	}
	if (LastState == 3 && NowState == 0)
	{
		Key_Number = 3;
	}
	if (LastState == 4 && NowState == 0)
	{
		Key_Number = 4;
	}
}
